//
//  ViewController.swift
//  BBImageDecoder
//
//  Created by zys on 05/06/2022.
//  Copyright (c) 2022 zys. All rights reserved.
//

import UIKit
import BBImageDecoder

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let imageView = UIImageView(frame: CGRect(x: 0, y: 200, width: view.bounds.size.width, height: view.bounds.size.width / 3024.0 * 4032.0))
//        imageView.image = UIImage(named: "IMG_2319")
        
//        if let url = Bundle.main.url(forResource: "th", withExtension: "jpeg") {
//            print(url)
//            imageView.image = BBImageDecoder.downsample(imageAt: url, to: imageView.frame.size, scale: 2)
//        }

//        if let data:Data = UIImage(named: "IMG_2319")?.jpegData(compressionQuality: 1) {
//            imageView.image = BBImageDecoder.downsample(imageAt: data, to: imageView.frame.size, scale: 2.0)
//        }
        
        if #available(iOS 10.0, *) {

            let image = UIImage.init(named: "IMG_2319")
            let drawImageView = UIImageView(image: image)
            drawImageView.frame = CGRect(x: 0, y: 0, width: view.bounds.size.width, height: view.bounds.size.width/drawImageView.frame.size.width * drawImageView.frame.size.height)
            imageView.image = BBImageDecoder.rerender(at: drawImageView, to: drawImageView.bounds.size)
        } else {
            // Fallback on earlier versions
        }
        
        view.addSubview(imageView)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

